#conding = utf-8
from handle.register_handle import RegisterHandle

class RegisterBusiness(object):
    def __init__(self,driver):
        self.register_h = RegisterHandle(driver)
    #执行操作页面元素-执行value输入
    def user_base(self,phone,code,phone_code,password,confirm_password):
        self.register_h.send_phone(phone)
        self.register_h.send_code(code)
        self.register_h.send_phone_code(phone_code)
        self.register_h.send_password(password)
        self.register_h.send_confirm_password(confirm_password)
        
    #判断是否执行注册成功，注册成功后肯定没有了注册按钮的文字
    def register_success(self):
        if self.register_h.get_register_button_text() ==None:
            return True
        else:
            False

    #电话号码输入错误 #找不到元素信息返回none 如果文字出现，用例执行成功
    def get_phone_error(self,phone,code,phone_code,password,confirm_password):
        self.user_base(phone,code,phone_code,password,confirm_password)
        if self.register_h.get_register_error("phone_error","格式有误，请重新输入") == None:
            # print("电话号码检验不成功")
            return True
        else:
            return False

    #图片验证码输入错误
    def get_code_error(self,phone,code,phone_code,password,confirm_password):
        self.user_base(phone,code,phone_code,password,confirm_password)
        if self.register_h.get_register_error("code_error","验证码错误") == None:
            # print("图片验证码检验不成功")
            return True
        else:
            return False

    #手机短信验证码错误
    def get_phone_code_error(self,phone,code,phone_code,password,confirm_password):
        self.user_base(phone,code,phone_code,password,confirm_password)
        if self.register_h.get_register_error("phone_code_error","验证码错误，请重新填写") == None:
            # print("短信验证码检验不成功")
            return True
        else:
            return False

    #输入密码错误
    def get_password_error(self,phone,code,phone_code,password,confirm_password):
        self.user_base(phone,code,phone_code,password,confirm_password)
        if self.register_h.get_register_error("password_error","格式有误，请重新输入。") == None:
            # print("输入密码格式有误，检验不成功")
            return True
        else:
            return False

    #确认密码错误
    def get_confirm_password_error(self,phone,code,phone_code,password,confirm_password):
        self.user_base(phone,code,phone_code,password,confirm_password)
        if self.register_h.get_register_error("confirm_password_error","密码不一致，请重新输入。") == None:
            # print("确认密码有误，检验不成功")
            return True
        else:
            return False

    #数据驱动，执行此条case为主线
    def register_function(self,phone,code,phone_code,password,confirm_password,assertCode,assertText):
        self.user_base(phone,code,phone_code,password,confirm_password)
        if self.register_h.get_register_error(assertCode,assertText)==None:
            return True
        else:
            return False   

    
    

    
